﻿using System;
namespace Producers.Ehma10000000.Xtee.Riik.Ee.Producer.Ehma10000000 {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="kam2List", Namespace="http://producers.ehma-10000000.xtee.riik.ee/producer/ehma-10000000", Target=typeof(Kam2List))]
    public class Kam2ListSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IKam2List clazz;
        
        public Kam2ListSerializer(IKam2List clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            for (int x = 0; ((clazz.Kam2 != null) 
                        && (x < clazz.Kam2.Count)); x = (x + 1)) {
                if (clazz.Kam2[x]!=null) {
                    Writer.WriteStartElement("kam2");
                    global::Xtee.Core.SerializationMetadata metaKam2 = this.GetMetaData(clazz.Kam2[x]);
                    Writer.WriteTypeAttribute(metaKam2.TypeQualifiedName.Namespace, metaKam2.TypeQualifiedName.Name);
                    metaKam2.NewSerializer(clazz.Kam2[x]).WriteXml(Writer);
                    Writer.WriteEndElement();
                }
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="kam2") {
                clazz.Kam2 = new System.Collections.Generic.List<global::Producers.Ehma10000000.Xtee.Riik.Ee.Producer.Ehma10000000.IKam2>();
                for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                            && (Reader.LocalName == "kam2")); ) {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>kam2List>kam2");
                    }
                    global::Xtee.Core.SerializationMetadata metaKam2 = this.GetMetaData<global::Producers.Ehma10000000.Xtee.Riik.Ee.Producer.Ehma10000000.IKam2>(Reader, "kam2", "http://producers.ehma-10000000.xtee.riik.ee/producer/ehma-10000000");
                    global::Producers.Ehma10000000.Xtee.Riik.Ee.Producer.Ehma10000000.IKam2 item = metaKam2.NewEntity<global::Producers.Ehma10000000.Xtee.Riik.Ee.Producer.Ehma10000000.IKam2>();
                    clazz.Kam2.Add(item);
                    if ((Reader.IsEmptyElement == false)) {
                        Reader.ReadStartElement("kam2");
                        metaKam2.NewSerializer(item).ReadXml(Reader);
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
            }
        }
    }
}
